﻿CREATE PROCEDURE [SSIS].[CreateSolutionEnvironment](
	@EnvironmentName sysname,
	@EnvironmentDescription nvarchar(1024) = N'',
	@SolutionFolderName sysname
)
AS
BEGIN
	IF EXISTS(
		SELECT * FROM [$(SSISDB)].[catalog].[environments] AS env
		INNER JOIN [$(SSISDB)].[catalog].[folders] AS fld
			ON (fld.[folder_id] = env.[folder_id])
			AND(fld.[name] = @SolutionFolderName)
		WHERE (env.[name] = @EnvironmentName)
	)
		BEGIN
			RETURN;
		END

	EXEC [$(SSISDB)].[catalog].[create_environment]
		@environment_name = @EnvironmentName,
		@environment_description = N'',
		@folder_name = @SolutionFolderName;
END
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = N'This procedure will create a SSIS environment in the specified solution folder.', @level0type = N'SCHEMA', @level0name = N'SSIS', @level1type = N'PROCEDURE', @level1name = N'CreateSolutionEnvironment';

